<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        function fun() {
            var age = 19, sex = '男', num = 1001;
            var obj = {
                getAge: function () {
                    return age;
                },
                setAge: function (newAge) {
                    if (newAge < 0 || newAge > 120) {
                        console.log('超出限定范围');
                        return false;
                    }
                    age = newAge;
                }
            }
            return obj;
        }
        var p1 = fun();
        p1.setAge(-1);
        console.log(p1.getAge());
        function fun1() {
            var data = [];
            return {
                add: function (obj) {
                    for (var i = 0; i < arguments.length; i++) {
                        data.push(arguments[i]);
                    }
                },
                remove: function () {
                    data.shift();
                },
                getData: function () {
                    return data;
                }
            }
        }
        var objFn = fun1();
        objFn.add({ name: '王宝强' }, 1, '字符串', true);
        console.log(objFn.getData());
        objFn.remove();
        objFn.remove();
        console.log(objFn.getData());
        // [foo, fun, fn];
    </script>
</body>

</html>